/*
 * @Description: http模板
 * @Author: 小雨
 * @Date: 2024-06-26 11:19:26
 * @LastEditTime: 2024-06-26 11:38:15
 * @LastEditors: 小雨
 */

const http = require('http');

const server = http.createServer();

server.on('request', (req, res) => {
    let url = req.url;
    let content = `<h1>404找不到资源</h1>`;
    if (url === '/' || url === '/index') {
        content = `<h1>index首页</h1>`;
    }
    if (url === '/about') {
        content = `<h1>about关于页面</h1>`;
    }
    //需要中文兼容一下
    res.setHeader('Content-Type', 'text/html; charset=utf-8');
    res.end(content);
});

server.listen(80, () => {
    console.log('服务器启动成功');
});
